package io.renren.utils.util;

import java.util.ArrayList;
import java.util.Collection;

public class PageObject extends ArrayList {
	/**
	 * 
	 */
	private static final long serialVersionUID = -3689270015234068687L;

	private int totalRows;

	private int currentPage;

	private int totalPages;

	private int rowsPerPage;

	private String orderBy;

	public PageObject(Collection c, int totalRows, int currentPage, int rowsPerPage) {
		super(c);
		setTotalRows(totalRows);
		setRowsPerPage(rowsPerPage);
		setCurrentPage(currentPage);
		init();
	}

	public void init() {
		// int n = totalRows % rowsPerPage;
		// setTotalPages((totalRows - n) / rowsPerPage + 1);
		setTotalPages((totalRows - 1) / rowsPerPage + 1);
	}

	public void setTotalRows(int totalRows) {
		if (totalRows < 0)
			totalRows = 0;
		this.totalRows = totalRows;
	}

	public void setCurrentPage(int currentPage) {
		if (currentPage < 1)
			currentPage = 1;
		this.currentPage = currentPage;
	}

	public void setRowsPerPage(int rowsPerPage) {
		if (rowsPerPage < 1)
			rowsPerPage = 10;
		this.rowsPerPage = rowsPerPage;
	}

	public int getTotalRows() {
		return totalRows;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public int getRowsPerPage() {
		return rowsPerPage;
	}

	public int getTotalPages() {
		return totalPages;
	}

	public void setTotalPages(int totalPages) {
		this.totalPages = totalPages;
	}

	public String getOrderBy() {
		return orderBy;
	}

	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}

}
